<template>
	<view>
		<navigation-bar></navigation-bar>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">课表管理</block>
			<block slot="right" class="text">
			</block>
		</cu-custom>
		<wyb-table :defaultColWidth="ColWidth" :width="fullWidth" :minHeight="minHeight" :fontSize="fontSize" :height="fullHeight"
		 ref="table" :headers="headers" :contents="contents" :url-col="urlCol" :firstLineFixed="true" />
	</view>
</template>

<script>
	import DropdownMenu from '@/components/JP-dropdown-menu/JP-dropdown-menu.vue';
	import DropdownItem from '@/components/JP-dropdown-menu/JP-dropdown-item.vue';
	import wybTable from '@/components/wyb-table/wyb-table.vue'

	export default {
		components: {
			DropdownMenu,
			DropdownItem,
			wybTable,
		},
		onLoad(options) {},

		data() {
			const theUrl = '/pages/demos/noticeBar-demo/more' // 本地的某个页面
			const httpUrl = 'https://ext.dcloud.net.cn/plugin?id=2667' // 某个网址
			return {
				ColWidth: document.documentElement.clientWidth / 5,
				minHeight: [15, 30],
				fontSize: [14, 13],
				headers: [{
					label: '课时',
					key: 'classHour'
				}, {
					label: '周一',
					key: 'monday'
				}, {
					label: '周二',
					key: 'tuesday'
				}, {
					label: '周三',
					key: 'wednesday'
				}, {
					label: '周四',
					key: 'thursday'
				}, {
					label: '周五',
					key: 'friday'
				}, {
					label: '周六',
					key: 'saturday'
				}, {
					label: '周日',
					key: 'sunday'
				}],
				contents: [{
					classHour: {
						"id": 1,
						"classHourName": "第一节",
						"classHourTime": "08:00-08:45",
						"creator": "陆胡江",
						"createTime": "2020-09-10T21:16:29.000+00:00"
					},
					monday: {
						"courseId": 1,
						"subName": "机械管理",
						"subId": 1,
						"teacherId": 4,
						"teacherName": "陆胡江",
						"isDoubleWeek": "0"
					},
					tuesday: null,
					wednesday: null,
					thursday: null,
					friday: null,
					saturday: {
						"courseId": 6,
						"subName": "园林设计",
						"subId": 2,
						"teacherId": 10,
						"teacherName": "周总",
						"isDoubleWeek": "true"
					},
					sunday: null
				}],
				urlCol: [{
					type: 'route',
					key: 'url'
				}, {
					type: 'http',
					key: 'link'
				}],
				fullWidth: document.documentElement.clientWidth + "px",
				fullHeight: (document.documentElement.clientHeight - 90) + "px",


			}
		},
		created() {
			window.addEventListener('resize', this.handleResize)
		},
		beforeDestroy: function() {
			window.removeEventListener('resize', this.handleResize)
		},
		onLoad: function(options) {
			this.loadData()
		},
		methods: {
			loadData(){
				let data = {
					"classId": 1,
				}
				console.log(data)
				//获取课表
				this.loading = true;
				this.$api.selectCourses(data).then((res) => {
					console.log('selectCourses')
					console.log(res)
					this.loading = false;
					if (res.code == null) { //成功
					this.contents = res
					} else {
						console.log("getUserInfo code：" + res.code)
					}
				
				}).catch((err) => {
					this.loading = false;
					console.log('request fail', err);
				})
			},
			handleResize(event) {
				this.fullWidth = document.documentElement.clientWidth + "px"
				this.fullHeight = (document.documentElement.clientHeight - 90) + "px"
				this.ColWidth = document.documentElement.clientWidth / 5
				console.log(document.documentElement.clientHeight)
			},
		}
	}
</script>

<style>
	.text {
		font-size: 12x;
		font-style: initial;
		color: #0081FF;
	}
</style>
